package uppacket

import (
	"gitee.com/yanwc/ebicycle/device/frame"
	"gitee.com/yanwc/ebicycle/device/internal/codec"
	"gitee.com/yanwc/ebicycle/device/internal/field"
	"gitee.com/yanwc/ebicycle/device/server"
	"gitee.com/yanwc/ebicycle/device/utils"

	"github.com/panjf2000/gnet"
)

type WarnPacket struct{}

var _ IPacket = (*WarnPacket)(nil)

func (hbp *WarnPacket) Do(frame frame.IFrame, c gnet.Conn) ([]byte, gnet.Action, error) {
	var warn field.WarnType
	utils.LoadPacket(frame.PayloadData(), warn[:])
	if d, ok := server.SessionDevices.GetWithConn(c); ok {
		go d.Notify(warn[0])
	}

	f := &codec.Frame{
		CmdWord: frame.GetCmdWord(),
		SN:      frame.GetSN(),
	}
	return f.WrapPacket(nil), gnet.None, nil
}
